-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some utility to IO class #137
Conversation
Add originzation. Add a Enum class to speified use Output & Input. Add a clear_content to clear Output & Input file.
including IO.File Enum class
Add some notes Add a flag make_dirs to ensure the dir has created/ Fix some bug.
d4744b3
to
2727298
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自动创建路径一般default to false吧 免得有人写错了还找不到问题在哪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不过你这个make_dirs起到啥实际作用了吗
如果prefix 包含路径: 改了,makedir默认为False 比如: |
Set make_dirs default value to False
我本地测试是没有问题的,会自动创建目录 |
你测试为false的时候会不会报错了吗 |
哦,忘了加条件判定了。。。 |
Add logic to check make_dirs flag
OK |
Add forget flag make_dirs in __init_file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
提交前不再处理一下ide的错误和警告信息吗
怎么还能有缺失参数的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
算了我给你修了
刚刚看到了,现在没问题 |
OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦我终于看懂你想干什么了
你把input和output的相关函数都合并起来了
我感觉没啥特别的意义啊
而且这个是破坏性的更新
cyaron/io.py
Outdated
file.truncate(pos) | ||
|
||
|
||
def write(self, file: File = File.INPUT, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这是啥逻辑
如果file=File.OUTPUT还要往input_file写吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哪里?引用位置不正确吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write方法
现在改 |
Fix: file cannot specified
OK |
测试正常 |
|
怎么说呢 对原有 api 大刀阔斧修改的 pr 我原则上是不想合并的 总不能升级个包然后全炸了吧 |
而且感觉你的逻辑有点乱 要不要先 draft 掉然后 rebase 回去重新写 |
ok |
Restore the origin api.
OK |
现在仅添加了clear_content&make_dirs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class TestIO(unittest.TestCase):
def test_output_clear_content(self):
with IO("test_clear.in", "test_clear.out") as test:
test.input_write("This is a test.")
test.input_clear_content()
test.input_write("Cleared content.")
test.output_write("This is a test.")
test.output_clear_content()
test.output_write("Cleared content.")
with open("test_clear.in", encoding="utf-8") as f:
input_text = f.read()
with open("test_clear.out", encoding="utf-8") as f:
output_text = f.read()
self.assertEqual(input_text, "Cleared content.")
self.assertEqual(output_text, "Cleared content.")
是这么用的吗 为啥我写的test没过
AssertionError: '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 Cleared content.' != 'Cleared content.'
Add forget seek() for clear
OK, truncate后面忘写seek了,导致前面的都是0x00(空) |
正在改,原因:is_first_char 没有正确设置。 |
test结果好像还是不太对
为啥会多一个空格 你那边有这种行为吗 |
正在改,问一下,truncate后如果最后一个字符是空格,默认添加数据不加空格吗? |
现在的实现逻辑,你看行不: |
Fix: truncated file will more a space
Fixed |
要不重新截断之后直接把空格干掉吧 |
Ok,如果有末尾有空格直接删除? |
我意思是 别考虑空格问题了 截断之后直接当成新一行处理 |
OK, Fixing |
Always set is_first_char[file] to True, igrone space problem (Review from PR)
Fixed |
咱要不提交的时候在本地测试一下? |
我没链接到本地编译器,都是在Github上改的... |
那你用codespace也行啊。。。 |
下次一定 |
先draft掉了 等你写好了repoen就可以 |
行,我先测试下 |
测试完成(IOTest successful 11/11) |
Add a flag make_dirs (to ensure that the folder has been created, if not it will create it)
Add a function clear_content (to truncate the content after position (default is 0))
Add a Enum Class File to clearly show what file would to change
Only modified the IO.py and init.py(import new statement)
添加一个选项make_dirs(以确保文件的上层文件夹已创建,否则将创建它)
添加函数IO.clear_content(截断位置后的内容(默认值为0))
添加枚举类File,以清楚地显示要更改的文件
仅修改了IO.py和__init__.py(导入新语句)